#!/bin/bash

prePath=/home/data/sftp/charmdmp/charm/upload/mobile/
preFile=Charm_mobile_
endFile=.log.gz
gz="gz"

#copy file from source
mkdir decompress
for i in 1 2 3 4 5 6 7
do
	filePath=$prePath$preFile$(date "+%Y%m%d" --date="$i"' day ago')$endFile
#	echo $filePath
	cp $filePath ./decompress
done

#gzip -d 
for file in decompress/*
do 
	if test -f $file
	then
		if [ "$gz" = "${file##*.}" ]
		then
			gzip -d $file
		fi
	fi
done


#wash and sort
mkdir filedone
for file in decompress/*
do 
	if test -f $file
	then
		./washAndSort $file filedone/${file##*/}
	fi
done


hadoopPath="/DMP/test/zp/charm_input/"
hadoop fs -rm $hadoopPath"*"
hadoop fs -put filedone/* $hadoopPath

charm_output="/DMP/test/zp/charm_output"
hadoop fs -rmr $charm_output

#input list
prefix="/DMP/instance/1/hera/job/predict/7/"
mzhenInput=""
for i in 2
do
	mzhenInput=$mzhenInput$prefix$(date "+%Y%m%d" --date="$i"' day ago')"1700/"
done
#mzhenInput=$mzhenInput$prefix$(date "+%Y%m%d" --date='7 day ago')"*"
echo "charmInput:"$hadoopPath
echo "mzhenInput:"$mzhenInput
hadoop jar hadoop1.0-1.0-SNAPSHOT.jar crossjob.CrossJob \
-Dmyjob.charm_input=$hadoopPath \
-Dmyjob.mzhen_input=$mzhenInput \
-Dmyjob.output=$charm_output \
-Dmapreduce.job.queuenname=dmp \
-Dmapreduce.job.priority=VERY_HIGH

result=$(date "+%Y%m%d")
hadoop fs -getmerge $charm_output"/*" $result".txt"
scp $result".txt" dmp@www.charmdmp.com:/home/data/third-party-tag/mz/mb/

charmlog=$(date "+%Y%m%d" --date='7 day ago')"-"$result
mzhenLogDate=$(date "+%Y%m%d" --date='1 day ago')
echo $charmlog
java -cp testJava-1.0-SNAPSHOT.jar com.test.ChramLogStatic tagExp.txt $result".txt" $mzhenLogDate"1700" $charmlog
rm $result".txt"
echo "success!"

rm -rf decompress
rm -rf filedone
exit 0
